package com.zh.junit.dao.repository;

import com.zh.junit.dao.entity.BookEntity;
import jakarta.validation.constraints.NotEmpty;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.ListCrudRepository;

import java.util.List;

/**
 * @author ZH
 * @date 12:02 2023/2/28
 */

public interface BookRepository extends ListCrudRepository<BookEntity,Long> {

    @Query("SELECT book FROM BookEntity book WHERE book.title like CONCAT('%',:title,'%')")
    List<BookEntity> findByTitleLike(String title);

    @Query("SELECT count()>0 AS flag FROM BookEntity book WHERE book.title=:title")
    boolean existsByTitle(String title);
}

